<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="/jquery-3.6.0.min.js"></script>
<body>
    <table >
        <th colspan="4">
            <td>页面查询</td>
        </th>
        <tr>
            <td>id</td>
            <td>name</td>
            <td>age</td>
            <td>sex</td>
			<td>操作</td>
        </tr>

    </table>
</body>
</html>
<script type="text/javascript">
	$(function(){
		/* $.getJSON("/insert1",{
			id:0,
			name:"小虎",
			age:18,
			sex:"男"
		},function(){
			
		}) */
			
			
		
		//整个页面加载完成再执行
		$.get("/findAll","",function(result){
			for(user of result){
				console.log(user)
				$("table").html($("table").html()+"<tr><td>"+user.id+"</td><td>"+user.name+"</td><td>"+user.age+"</td><td>"+user.sex+"</td>	"
				 +"<td><button type='button' onclick='change("+user.id+")'>修改</button><button type='button' onclick='delete1("+user.id+")'>删除</button></td></tr>");
			}
			
		},"json");

	})
	function change(id){
		console.log("修改"+id+"行")
		$.ajax({
			url:"update",
			type:"post",
			data:{
				id:id,
				name:"张三"
			},
		success:function(){
			$.get("/findAll","",function(result){
				
			},"json");
		}
		})
	}
	function delete1(id){
		console.log("删除"+id+"行")
		$.ajax({
			url:"delete",
			type:"post",
			data:{
				id:id
			},
		success:function(){
			$.get("/findAll","",function(result){
				
			},"json");
		}
		})
	}
</script>